﻿using System;

using EHSubmit.Model;
using EHSubmit.Util;
using Newtonsoft.Json.Linq;


namespace EHSubmit.Logic.Services
{
    /// <summary>
    /// 远程用户服务代理默认实现类
    /// </summary>
    public class RemoteUserProxyImpl : IRemoteUserProxy
    {
        public RemoteUserProxyImpl()
        {
        }


        /// <summary>
        /// 远程验证用户
        /// </summary>
        /// <param name="id">用户ID</param>
        /// <param name="pwd">用户密码(明文)</param>
        /// <param name="type">用户类型</param>
        /// <returns>用户对象,验证失败返回空</returns>
        public User Check(string id, string pwd, int type)
        {
            User user = null;

            try
            {
                EHSubmit.Remote.DataProvider dp = new EHSubmit.Remote.DataProvider();

                string json = dp.GetUser(id, pwd, type);

                user = DataConverter.ParseUser(json);

            }
            catch (System.Net.WebException we)
            {
                LogHelper.Log("教务管理系统连接错误", we);

                throw new SysException("教务管理系统连接错误");
            }
         
            return user;
        }

    }
}